﻿Public Class frmAD_CapNhatDangKy 
    Public _dkDTO As New DangKyDTO
    Public _dkBUS As New DangKyBUS
    Public _svDTO As New SinhVienDTO
    Public _svBUS As New SinhVienBUS
    Public tableLoaiNha As New DataTable
    Public tableKhuVuc As New DataTable
    Public tableDangKy As New DataTable
    Private Sub frmAD_CapNhatDangKy_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load        
        If _dkDTO.TrangThai = 1 Then
            cbTrangThai.Items.Add("Đã duyệt")
        ElseIf _dkDTO.TrangThai = 2 Then
            cbTrangThai.Items.Add("Chưa duyệt")
        ElseIf _dkDTO.TrangThai = 3 Then
            cbTrangThai.Items.Add("Tạm đóng")
        ElseIf _dkDTO.TrangThai = 4 Then
            cbTrangThai.Items.Add("Đã xóa")
        End If
        cbTrangThai.Items.Add("Đã duyệt")
        cbTrangThai.Items.Add("Chưa duyệt")
        cbTrangThai.Items.Add("Tạm đóng")
        cbTrangThai.Items.Add("Đã xóa")
        cbTrangThai.SelectedIndex = 0
        '---------------------------------------------
        txtDienTich.Text = _dkDTO.DienTich
        txtTieuDe.Text = _dkDTO.TieuDe
        txtGiaThue.Text = _dkDTO.GiaThue
        '----------------------------------------------------------------------------------------------------
        Dim loaiNhaDTO As New LoaiNhaDTO
        Dim loaiNhaBUS As New LoaiNhaBUS
        '----------------------------------------------------------------------------------------------------
        Dim loaitinDTO As New LoaiTinDTO
        Dim loaitinBUS As New LoaiTinBUS
        '----------------------------------------------------------------------------------------------------
        Dim kvDTO As New KhuVucDTO
        Dim kvBUS As New KhuVucBUS
        '----------------------------------------------------------------------------------------------------
        tableLoaiNha = loaiNhaBUS.GetAll()
        tableKhuVuc = kvBUS.GetAll()
        '------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            If Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString()) = _dkDTO.MaLoaiNha Then
                cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
                Exit For
            End If
        Next
        cbLoaiNha.SelectedIndex = 0
        '---------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            If tableKhuVuc.Rows(i)("TenKhuVuc").ToString() = kvDTO.TenKhuVuc Then
                cbKhuVuc.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
                Exit For
            End If
        Next
        '----------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            cbKhuVuc.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
        Next
        cbKhuVuc.SelectedIndex = 0
        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
        Next

        '----------------------------------------------------------------------------------------------------
        cbSuaChua.Items.Add(_dkDTO.SucChua)
        cbSuaChua.SelectedIndex = 0
        '----------------------------------------------------------------------------------------------------
        For i As Integer = 1 To 10
            If i <> _dkDTO.SucChua Then
                cbSuaChua.Items.Add(i.ToString())
            End If
        Next
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.ChoNamThue = 1 Then
            ckChoNamThue.Checked = True
        Else
            ckChoNamThue.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.ChoNuThue = 1 Then
            ckChoNuThue.Checked = True
        Else
            ckChoNuThue.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.ChoNauAn = 1 Then
            ckNauAn.Checked = True
        Else
            ckNauAn.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.OChungChu = 1 Then
            ckChungChu.Checked = True
        Else
            ckChungChu.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.GanCho = 1 Then
            ckGanCho.Checked = True
        Else
            ckGanCho.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.OGhep = 1 Then
            ckOGhep.Checked = True
        Else
            ckOGhep.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.Internet = 1 Then
            ckInternet.Checked = True
        Else
            ckInternet.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.TruyenHinhCap = 1 Then
            ckTruyenHinhCap.Checked = True
        Else
            ckTruyenHinhCap.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.GanTramXeBuyt = 1 Then
            ckXeBuyt.Checked = True
        Else
            ckXeBuyt.Checked = False
        End If
    End Sub

    Private Sub btnCapNhat_Click(sender As System.Object, e As System.EventArgs) Handles btnCapNhat.Click
        Dim result As DialogResult = MessageBox.Show("Bạn có chắc chắn muốn thực hiện cập nhật?", "Thông báo", MessageBoxButtons.YesNo)
        If result = DialogResult.Yes Then
            '--------------------------------------------------------------------------------------------------------------------
            For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
                If tableLoaiNha.Rows(i)("TenLoaiNha").ToString() = cbLoaiNha.Text Then
                    _dkDTO.MaLoaiNha = Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString())
                    Exit For
                End If
            Next
            '-----------------------------------------------------------------------------------------------------
            For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
                If tableKhuVuc.Rows(i)("TenKhuVuc").ToString() = cbKhuVuc.Text Then
                    _dkDTO.MaKhuVucThue = Convert.ToInt32(tableKhuVuc.Rows(i)("MaKhuVuc").ToString())
                    Exit For
                End If
            Next
            '--------------------------------------------------------------------------------------------------------
            If ckXeBuyt.Checked = True Then
                _dkDTO.GanTramXeBuyt = 1
            Else
                _dkDTO.GanTramXeBuyt = 0
            End If
            If ckOGhep.Checked = True Then
                _dkDTO.OGhep = 1
            Else
                _dkDTO.OGhep = 0
            End If
            If ckNauAn.Checked = True Then
                _dkDTO.ChoNauAn = 1
            Else
                _dkDTO.ChoNauAn = 0
            End If
            If ckChungChu.Checked = True Then
                _dkDTO.OChungChu = 1
            Else
                _dkDTO.OChungChu = 0
            End If
            If ckInternet.Checked = True Then
                _dkDTO.Internet = 1
            Else
                _dkDTO.Internet = 0
            End If
            If ckTruyenHinhCap.Checked = True Then
                _dkDTO.TruyenHinhCap = 1
            Else
                _dkDTO.TruyenHinhCap = 0
            End If
            If ckGanCho.Checked = True Then
                _dkDTO.GanCho = 1
            Else
                _dkDTO.GanCho = 0
            End If
            If ckChoNamThue.Checked = True Then
                _dkDTO.ChoNamThue = 1
            Else
                _dkDTO.ChoNamThue = 0
            End If
            If ckChoNuThue.Checked = True Then
                _dkDTO.ChoNuThue = 1
            Else
                _dkDTO.ChoNuThue = 0
            End If
            '--------------------------------------------------------------------------------------------------------------------
            _dkDTO.DienTich = Convert.ToSingle(txtDienTich.Text)
            _dkDTO.GiaThue = Convert.ToInt32(txtGiaThue.Text)
            _dkDTO.SucChua = Convert.ToInt32(cbSuaChua.Text)
            _dkDTO.TieuDe = txtTieuDe.Text
            'If _dkDTO.TrangThai = 1 Then
            '    cbTrangThai.Items.Add("Đã duyệt")
            'ElseIf _dkDTO.TrangThai = 2 Then
            '    cbTrangThai.Items.Add("Chưa duyệt")
            'ElseIf _dkDTO.TrangThai = 3 Then
            '    cbTrangThai.Items.Add("Tạm đóng")
            'ElseIf _dkDTO.TrangThai = 4 Then
            '    cbTrangThai.Items.Add("Đã xóa")
            'End If
            'cbTrangThai.Items.Add("Đã duyệt")
            'cbTrangThai.Items.Add("Chưa duyệt")
            'cbTrangThai.Items.Add("Tạm đóng")
            'cbTrangThai.Items.Add("Đã xóa")
            'cbTrangThai.SelectedIndex = 1
            For i As Integer = 0 To 4
                If cbTrangThai.Text = "Đã duyệt" Then
                    _dkDTO.TrangThai = 1
                ElseIf cbTrangThai.Text = "Chưa duyệt" Then
                    _dkDTO.TrangThai = 2
                ElseIf cbTrangThai.Text = "Tạm đóng" Then
                    _dkDTO.TrangThai = 3
                ElseIf cbTrangThai.Text = "Đã xóa" Then
                    _dkDTO.TrangThai = 4
                End If
            Next
            '-------------------------------------------------------------------------------------------------------
            _dkBUS.Update(_dkDTO)
            tableDangKy = _dkBUS.GetAll()
            frmQuanTri.dgvDangKy.DataSource = tableDangKy
            frmQuanTri.dgvDangKy.Show()
            Me.Close()
        End If
    End Sub

    Private Sub SimpleButton2_Click(sender As System.Object, e As System.EventArgs) Handles SimpleButton2.Click
        Me.Close()
    End Sub
End Class